﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace Eniux.Windows.Controls.Core.Core
{
    public class AttachDataGrid : AttachBase
    {
        #region 附加属性列表头是否被点击
        public static readonly DependencyProperty IsPressedDataGridColumnHeaderProperty = DependencyProperty.RegisterAttached("IsPressedDataGridColumnHeader", typeof(bool), typeof(AttachDataGrid), new PropertyMetadata(false, IsPressedDataGridColumnHeaderPropertyChanged));
        private static void IsPressedDataGridColumnHeaderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DataGridColumnHeader dg = (DataGridColumnHeader)d;
            if (dg != null &&dg.Column!=null&&dg.Column.CellStyle!=null)
            {
                Setter set = new Setter(DataGridCell.IsSelectedProperty, (bool)e.NewValue);
                Style style = new Style();
                style.TargetType = typeof(DataGridCell);
                style.Setters.Add(set);
                style.BasedOn = dg.Column.CellStyle;
                dg.Column.CellStyle = style;

            }
            
        }
        public static void SetIsPressedDataGridColumnHeader(DependencyObject element, bool value)
        {
            element.SetValue(IsPressedDataGridColumnHeaderProperty, value);
        }
        public static bool GetIsPressedDataGridColumnHeader(DependencyObject element)
        {
            return (bool)element.GetValue(IsPressedDataGridColumnHeaderProperty);
        }
        #endregion
    }
}
